<!DOCTYPE HTML>
<html>
<head>
   <meta charset="UTF-8" />
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="Access-Control-Allow-Origin" content="*">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
    <title>title</title>
    <script type="text/javascript" src="../../script/s94.js#debug"></script>
    <script type="text/javascript" src="../../script/s94.app.js"></script>
    <!--公共部分-->
    <script type="text/javascript" src="../../script/common.js"></script>
    <link href="../../css/common.css" rel="stylesheet" type="text/css" />
</head>
<style type="text/css">
	.body{font-size: 0.28rem;}
	.body .button{margin: 0.1rem;}
	.title{width: 100%;margin: 0.6rem 0 0.2rem 0;text-align: center;font-size: 0.36rem;font-weight: bold;}
</style>
<body>
	<header class="public">
		<a app href="back" target="_blank"><i ico class="ico-fx-l"></i></a>
		<div class="set-xy full">floatWebView模块测试</div>
	</header>
	<div class="body">
		<p class="title">APP中</p>
		
		<div class="button" act="test">测试</div>
		</br>

		<div class="button" act="create">创建</div>
		<div class="button" act="show">显示</div>
		<div class="button" act="hide">隐藏</div>
		<div class="button" act="remove">移除</div>
		
		<div class="button" act="offset">改变位置</div>
		<div class="button" act="size">改变大小</div>
		<div class="button" act="noTouch">不能触摸</div>
		<div class="button" act="noLimit">可以显示到屏幕外</div>
		<div class="button" act="center">居中</div>
		<div class="button" act="canFocus">可以获取焦点</div>
		<div class="button" act="followTouch">跟随触摸移动</div>
		<div class="button" act="stickSide">自动贴边</div>
		<div class="button" act="eval">在悬浮窗中执行js代码</div>
	</div>
</body>
<script type="text/javascript">
//每个方法传递的参数
var params = {
	create : {"name":"test","url":"widget://html/floatWebView/float.html"},
	show : {"name":"test"},
	hide : {"name":"test"},
	remove : {"name":"test"},
	
	offset : {"name":"test","x":200,"y":200},
	size : {"name":"test","w":200,"h":200},
	noTouch : {"name":"test","noTouch":true},
	noLimit : {"name":"test","noLimit":true},
	center : {"name":"test","center":true},
	canFocus : {"name":"test","canFocus":true},
	followTouch : {"name":"test","followTouch":true},
	stickSide : {"name":"test","stickSide":true},
	eval : {"name":"test","jsstring":'$(".eval-msg").text("app调用了eval接口");'},
}
$.app(function(){ //APP加载完成后执行回调函数，等效于apicloud的apiready方法
	var md = $.app("floatWebView");//等效于api.require("floatWebView");
	//所有按钮统一绑定事件
	$('.button[act]').on("click",function(){
		var act = $(this).attr("act"); //获取需要执行的方法名称
		var param = params[act]; //获取执行的方法需要传递的参数
		switch (typeof(param)) {
			case 'underfind': param = {};break;
			case 'function': param = param();break;
		}
		md[act](param, function(ret){
			tips(ret.msg);
			$.log(ret, act);
			if(!ret.status) return;
			switch (act) {
				case 'create':{
					if (ret.msg=='event') { //需要在创建悬浮窗的时候，绑定事件，便于悬浮窗向app传递数据或者执行app中的方法
						switch (ret.eventName){
							case 'msg':
							tips(ret.data?JSON.stringify(ret.data):'测试event');
								break;
						}
					}
				}break;
			}
		})
	})
})
</script>
</html>
